<template>
  <div>
    <el-dialog title="添加到仓库" :visible.sync="GoodsaddFlag">
  <el-form :model="GoodsaddBean">
    <el-form-item label="活动编号" :label-width="formLabelWidth">
      <el-input v-model="GoodsaddBean.code" autocomplete="off" readonly="readonly"></el-input>
    </el-form-item>
    <el-form-item label="活动名称" :label-width="formLabelWidth">
      <el-input v-model="GoodsaddBean.name" autocomplete="off" readonly="readonly"></el-input>
    </el-form-item>
    <el-form-item label="单位" :label-width="formLabelWidth">
      <el-input v-model="GoodsaddBean.unit" autocomplete="off" readonly="readonly"></el-input>
    </el-form-item>
    <el-form-item label="成本价" :label-width="formLabelWidth">
      <el-input v-model="GoodsaddBean.purchasingPrice" autocomplete="off" readonly="readonly"></el-input>
    </el-form-item>
    <el-form-item label="期初数量" :label-width="formLabelWidth">
      <el-input v-model="GoodsaddBean.inventoryQuantity" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="销售价格" :label-width="formLabelWidth">
      <el-input v-model="GoodsaddBean.sellingPrice" autocomplete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="GoodsaddFlag = false">取 消</el-button>
    <el-button type="primary" @click="addInventory">确 定</el-button>
  </div>
</el-dialog>
    <el-form :inline="true" :model="GoodsBean" class="demo-form-inline">
  <el-form-item label="审批人">
    <el-input v-model="GoodsBean.name" placeholder="审批人"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="getGoodsList(1)">查询</el-button>
  </el-form-item>
</el-form>
    <el-table :data="GoodsList" style="width: 100%" max-height="600">
      <el-table-column prop="id" label="编号" width="150"></el-table-column>
      <el-table-column prop="code" label="商品编码" width="250"></el-table-column>
      <el-table-column prop="name" label="商品名称" width="600"></el-table-column>
      <el-table-column prop="model" label="型号" width="150"></el-table-column>
      <el-table-column prop="unit" label="单位" width="50"></el-table-column>
      <el-table-column fixed="right" label="操作" width="300">
        <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="add(scope.row)">添加到仓库</el-button>
        </template>
      </el-table-column>
    </el-table>
<el-pagination @current-change="getGoodsList" :current-page="Goodspagination.pageNum" :page-count="Goodspagination.pages"></el-pagination>

      <el-table :data="InventoryList" style="width: 100%" max-height="600">
      <el-table-column prop="id" label="编号" width="150"></el-table-column>
      <el-table-column prop="code" label="商品编码" width="250"></el-table-column>
      <el-table-column prop="name" label="商品名称" width="400"></el-table-column>
      <el-table-column prop="model" label="型号" width="150"></el-table-column>
      <el-table-column prop="unit" label="单位" width="50"></el-table-column>
      <el-table-column prop="inventoryQuantity" label="库存数量" width="100"></el-table-column>
      <el-table-column prop="purchasingPrice" label="成本价" width="100"></el-table-column>
      <el-table-column prop="purchasingPrice" label="库存金额" width="100" :formatter="sumformatter"></el-table-column>
      <el-table-column fixed="right" label="操作" width="300">
        <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="updInvenoty(scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="delInventory(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @current-change="getInventoryList" :current-page="InventoryPagination.pageNum" :page-count="InventoryPagination.pages"></el-pagination>
    
    <el-dialog title="修改" :visible.sync="InventoryupdFlag">
      <el-form :model="InventoryupdBean">
        <el-form-item label="商品编号" :label-width="formLabelWidth">
          <el-input v-model="InventoryupdBean.code" autocomplete="off" readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="商品名称" :label-width="formLabelWidth">
          <el-input v-model="InventoryupdBean.name" autocomplete="off" readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="单位" :label-width="formLabelWidth">
          <el-input v-model="InventoryupdBean.unit" autocomplete="off" readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="成本价" :label-width="formLabelWidth">
          <el-input v-model="InventoryupdBean.purchasingPrice" autocomplete="off" readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="期初数量" :label-width="formLabelWidth">
          <el-input v-model="InventoryupdBean.inventoryQuantity" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="销售价格" :label-width="formLabelWidth">
          <el-input v-model="InventoryupdBean.sellingPrice" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="InventoryupdFlag = false">取 消</el-button>
        <el-button type="primary" @click="updInvent">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  methods: {
    getGoodsList:function(pageNo){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/goodList",
        params: {
          pageNo: pageNo,
          pageSize:5,
          access_token: localStorage.getItem("access_token"),
          name:this.GoodsBean.name
        },
      }).then(function(res) {
        window.console.log(res,"res")
        $this.GoodsList = res.data.obj.list;
        $this.Goodspagination = res.data.obj;
      });
    },
    getInventoryList:function(pageNo){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/repertoryList",
        params: {
          pageNo: pageNo,
          pageSize:5,
          access_token: localStorage.getItem("access_token"),
          name:this.InventoryBean.name
        },
      }).then(function(res) {
        window.console.log(res,"res")
        $this.InventoryList = res.data.obj.list;
        $this.InventoryPagination = res.data.obj;
      });
    },
    sumformatter:function(str){
      return str.inventoryQuantity*str.purchasingPrice
    },
    add:function(row){
        this.GoodsaddFlag=true
        row.sellingPrice=""
        row.inventoryQuantity=""
        this.GoodsaddBean=row
    },
    addInventory:function(row){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/addRepertory?access_token="+localStorage.getItem("access_token"),
        params:this.GoodsaddBean
      }).then(function(res) {
        window.console.log(res,"res")
        if(res.data.obj>1){
          $this.GoodsaddFlag=false
          $this.getGoodsList(1);
          $this.getInventoryList(1);
        }
      })
    },
    updInvenoty:function(row){
      this.InventoryupdBean=row
      this.InventoryupdFlag=true
    },
    updInvent:function(){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/updRepertory?access_token="+localStorage.getItem("access_token"),
        params:this.InventoryupdBean
      }).then(function(res) {
        window.console.log(res,"res")
          alert("修改成功")
          $this.InventoryupdFlag=false
          $this.getGoodsList(1);
          $this.getInventoryList(1);
      })
    },
    delInventory:function(row){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/delRepertory?access_token="+localStorage.getItem("access_token"),
        params:row
      }).then(function(res) {
        window.console.log(res,"res")
          alert("删除成功")
          $this.getGoodsList(1);
          $this.getInventoryList(1);
      })
    }
  },
  data() {
    return {
      GoodsList: [],
      Goodspagination:{},
      InventoryList:[],
      InventoryPagination:{},
      GoodsBean:{},
      GoodsaddFlag: false,
      GoodsaddBean:{},
      GoodsupdFlag: false,
      GoodsupdBean: {},
      formLabelWidth:'120px',
      InventoryBean:{},
      InventoryaddFlag: false,
      InventoryaddBean:{},
      InventoryupdFlag: false,
      InventoryupdBean: {},
    };
  },
  mounted() {
    this.getGoodsList(1);
    this.getInventoryList(1);
  }
};
</script>
